local ciyuanshenli = fk.CreateSkill {
  name = "ciyuanshenli",
}

Fk:loadTranslationTable{
  ["ciyuanshenli"] = "次元",
  [":ciyuanshenli"] = "你获得以下次元神力：<br/>"..
  "<font color=>跃影:你使用牌额外结算一次。<br/>"..
  "涅槃:你使用杀的次数+3 <br/>"..
  "破空:攻击无视护甲与防具 <br/>"..
  "湮空:造成伤害后阻止其下一次体力恢复</font>",

  ["@jbstg_anyezhouyin-recover"] = "阻止体力恢复",
}

ciyuanshenli:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ciyuanshenli.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
})

ciyuanshenli:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(target, MarkEnum.SlashResidue.."-turn", 3)
  end,
})


ciyuanshenli:addEffect(fk.BeforeHpChanged, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and data.damageEvent and data.damageEvent.from == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x=data.shield_lost or 0
    if x>0 then
      data.num = data.num - data.shield_lost
      data.shield_lost=0
    end
  end,
})

ciyuanshenli:addEffect(fk.TargetSpecified, {
  can_refresh = function (self, event, target, player, data)
    return player == target and data.card.trueName == "slash" and player:hasSkill(self.name)
     and data.to:isAlive()
  end,
  on_cost = Util.TrueFunc,
  on_refresh = function (self, event, target, player, data)
    data.to:addQinggangTag(data)
  end,
})

ciyuanshenli:addEffect(fk.Damage, {
  name = "ciyuanshenli",
  anim_type = "offensive",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n=1
    player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
     local damage = e.data.damageEvent
     if  damage and player == damage.from then
       room:setPlayerMark(data.to, "@jbstg_anyezhouyin-recover", 1)
     end
   end, Player.HistoryGame)
  end,
})

ciyuanshenli:addEffect(fk.PreHpRecover, {
  name = "#ciyuanshenli_delay",
  anim_type = "negative",
  events = {fk.PreHpRecover},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.PreHpRecover then
      return target:getMark("@jbstg_anyezhouyin-recover") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.PreHpRecover then
      room:setPlayerMark(target, "@jbstg_anyezhouyin-recover", 0)
      data:preventRecover()
    end
  end,
})

return ciyuanshenli